#ifndef _RCC_BASE_H_
#define _RCC_BASE_H_


#include "sys.h"







template <void (*ClockCmd)(uint32_t,FunctionalState),void (*ResetCmd)(uint32_t,FunctionalState),uint32_t RCCPerip>
class RCC_Perip
{
	public:
		void Enable(bool en=true)const
		{
			ClockCmd(RCCPerip,en?ENABLE:DISABLE);
		}
		
		void Reset(bool en=true)const
		{
		
			ResetCmd(RCCPerip,en?ENABLE:DISABLE);
		}
};





#define RCC_PERI_DEF(_BUS,_PERI)		RCC_Perip<RCC_##_BUS##PeriphClockCmd,RCC_##_BUS##PeriphResetCmd,RCC_##_BUS##Periph_##_PERI> _PERI##_
#define APB1_PERI_DEF(_PERI)		RCC_PERI_DEF(APB1,_PERI)


class RCC_Collecter
{
public:
	
	RCC_Collecter(){}
	
	//APB1,36M
	RCC_PERI_DEF(APB1,TIM2);
	RCC_PERI_DEF(APB1,TIM3);
	RCC_PERI_DEF(APB1,TIM4);
	RCC_PERI_DEF(APB1,TIM5);
	RCC_PERI_DEF(APB1,TIM6);
	RCC_PERI_DEF(APB1,TIM7);
	RCC_PERI_DEF(APB1,TIM12);
	RCC_PERI_DEF(APB1,TIM13);
	RCC_PERI_DEF(APB1,TIM14);
	RCC_PERI_DEF(APB1,WWDG);
	RCC_PERI_DEF(APB1,SPI2);
	RCC_PERI_DEF(APB1,SPI3);
	RCC_PERI_DEF(APB1,USART2);
	RCC_PERI_DEF(APB1,USART3);
	RCC_PERI_DEF(APB1,UART4);
	RCC_PERI_DEF(APB1,UART5);
	RCC_PERI_DEF(APB1,I2C1);
	RCC_PERI_DEF(APB1,I2C2);
	RCC_PERI_DEF(APB1,CAN1);
	RCC_PERI_DEF(APB1,CAN2);
	RCC_PERI_DEF(APB1,BKP);
	RCC_PERI_DEF(APB1,PWR);
	RCC_PERI_DEF(APB1,DAC);
	RCC_PERI_DEF(APB1,CEC);

		
	//APB2,72M
	RCC_PERI_DEF(APB2,AFIO);
	RCC_PERI_DEF(APB2,GPIOA);		
	RCC_PERI_DEF(APB2,GPIOB);
	RCC_PERI_DEF(APB2,GPIOC);
	RCC_PERI_DEF(APB2,GPIOD);
	RCC_PERI_DEF(APB2,GPIOE);
	RCC_PERI_DEF(APB2,GPIOF);
	RCC_PERI_DEF(APB2,GPIOG);		
	RCC_PERI_DEF(APB2,ADC1);		
	RCC_PERI_DEF(APB2,ADC2);		
	RCC_PERI_DEF(APB2,TIM1);		
	RCC_PERI_DEF(APB2,SPI1);		
	RCC_PERI_DEF(APB2,TIM8);		
	RCC_PERI_DEF(APB2,USART1);		
	RCC_PERI_DEF(APB2,ADC3);		
	RCC_PERI_DEF(APB2,TIM15);		
	RCC_PERI_DEF(APB2,TIM16);		
	RCC_PERI_DEF(APB2,TIM17);		
	RCC_PERI_DEF(APB2,TIM9);		
	RCC_PERI_DEF(APB2,TIM10);		
	RCC_PERI_DEF(APB2,TIM11);		
		

};


const RCC_Collecter RCCX;

	


#endif

